<template>
  <div>
    <el-dialog title="维修完成"
               :visible.sync="centerDialogVisible"
               center>
      <div style="text-align:right;color:darkorange;margin: auto; width: max-content; max-height: 100%">
        维修情况说明：<el-input v-model="in_expl"
                  class="input3"
                  placeholder="维修情况说明："
                  style="width: 200px"></el-input>
        <div style="text-align:center;">
          <el-button class="botton"
                     @click="centerDialogVisible = false">取 消
          </el-button>
          <el-button class="botton"
                     @click="stateChangeTo1()">确 定
          </el-button>
        </div>
      </div>
    </el-dialog>
    <div style="color: darkorange; font-size: small; height: 30px">
      <el-input v-model="to_labId"
                class="input"
                placeholder="机房"
                style="width: 150px"></el-input>&nbsp;
      <el-input v-model="to_des"
                class="input"
                placeholder="故障描述"
                style="width: 150px"></el-input>&nbsp;
      <template>
        <span class="block"
              style="margin-right: 5px;">
          <el-date-picker v-model="to_date"
                          class="input"
                          type="date"
                          style="width: 150px"
                          placeholder="选择日期">
          </el-date-picker>
        </span>
      </template>
      <el-button class="botton"
                 @click="load()">搜索</el-button>
    </div>
    <div style="margin-top: 8px; margin-bottom: 15px"></div>
    <div class="big">
      <el-table :data="tableData"
                :row-style="{ color: 'darkorange', height: '60px' }"
                border
                fit
                style="width: 100%">
        <el-table-column label="维修机房"
                         prop="labId"></el-table-column>
        <el-table-column :formatter="formatDate"
                         label="申请日期"
                         prop="date"></el-table-column>
        <el-table-column label="故障描述"
                         prop="des"></el-table-column>
        <el-table-column label="申请状态"
                         prop="stateString"></el-table-column>
        <el-table-column label="维修描述"
                         prop="expl"></el-table-column>
        <el-table-column fixed="right"
                         label="更改维修状态"
                         style="border: 1px solid darkorange"
                         width="120px">
          <template slot-scope="scope">
            <div>
              <el-button type="warning"
                         v-if="scope.row.state==0"
                         style="margin-right: 5px;"
                         @click="stateChangeTo2(scope.row)">维修中</el-button>
              <el-button type="success"
                         v-if="scope.row.state==2"
                         @click="toCheck(scope.row)">维修完成</el-button>
            </div>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div style="padding: 10px 0; text-align: center">
      <el-pagination :current-page="page"
                     :total="total"
                     background
                     class="white-list-tool"
                     layout="total,prev, pager, next, jumper"
                     @current-change="handleCurrentChange">
      </el-pagination>
    </div>
  </div>
</template>

<script>
import { mapState } from "vuex";
export default {
  computed: mapState(["user", "term", "token"]),
  data () {
    return {
      centerDialogVisible: false,
      tableData: [],
      total: 0,
      page: 1,

      in_row: '',
      to_labId: '',
      to_des: '',
      to_date: '',
      to_state: '',

      in_expl: '',

      multipleSelection: [],
    };
  },
  methods: {
    toCheck (row) {
      this.in_expl = ''
      this.in_row = row
      this.centerDialogVisible = true
    },
    async stateChangeTo2 (row) {
      await this.$http.put("/labRep", {
        id: row.id,
        state: 2
      }, { headers: { 'userId': this.token } }).then((res) => {
        if (res.data.success === true) { this.$message("实验室" + row.labId + "维修中") }
        else this.$message(res.data.errorMsg)
      })
      this.load()
    },
    async stateChangeTo1 () {
      await this.$http.put("/labRep", {
        id: this.in_row.id,
        expl: this.in_expl,
        state: 1
      }, { headers: { 'userId': this.token } }).then((res) => {
        if (res.data.success === true) { this.$message("实验室" + this.in_row.labId + "维修完成！") }
        else this.$message(res.data.errorMsg)
      })
      this.centerDialogVisible = false
      this.load()
    },
    load () {
      this.$http.post("/labRep/1", {
        userId: this.user.userId,
        labId: this.to_labId,
        des: this.to_des,
        date: this.to_date,
        page: this.page
      }, { headers: { 'userId': this.token } }).then((res) => {
        if (!res.data.success) { this.$message(res.data.errorMsg) }
        this.tableData = res.data.data
        this.total = res.data.total
      });
    },
    handleCurrentChange (page) {
      this.page = page;
      this.load();
    },
    formatDate (row, column) {
      let data = row[column.property]
      if (data == null) {
        return null
      }
      let dt = new Date(data)
      return dt.getFullYear() + '-' + (dt.getMonth() + 1) + '-' + dt.getDate()
    },
  },
  created () {
    this.load();
  },
};
</script>


<style scoped>
::v-deep .el-dialog {
  background-color: #525151;
  border: 1px solid darkorange;
}

::v-deep .el-dialog__title {
  color: darkorange;
  caret-color: transparent;
}

.input3 /deep/ .el-input__inner {
  margin-right: 5px;
  background-color: #525151;
  border: 1px solid darkorange;
  color: darkorange;
}

.input /deep/ .el-input__inner {
  background-color: #525151;
  border: 1px solid darkorange;
  color: darkorange;
  width: 150px;
}

.botton {
  color: darkorange;
  background-color: #525151;
  border-color: darkorange;
}

.botton:hover,
.botton:focus {
  background: rgb(255, 200, 133);
  border-color: darkorange;
  color: black;
}

.big {
  border: 1px solid darkorange;
}

::v-deep .el-table th {
  border: 1px solid darkorange !important;
  border-right: none !important;
  border-bottom: none !important;
  background-color: #525151;
}

::v-deep.el-table thead {
  color: darkorange;
  font-weight: 500;
  border: 1px solid darkorange;
}

::v-deep .el-table tr {
  background-color: #525151;
}

::v-deep .el-table td,
.building-top .el-table th.is-leaf {
  border: 1px solid darkorange;
  border-right: none !important;
}

::v-deep .el-table::before {
  border: 1px solid darkorange;
  height: 0;
}

::v-deep .el-table td,
.el-table th {
  text-align: center;
}

.el-input {
  width: 100px;
  margin-bottom: 20px;
}

.el-table {
  border: 1px solid darkorange;
  margin: 0 auto;
  font-size: 15px;
}
</style>